<!DOCTYPE html>
<html lang="en"
    xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <!--jquery-->
    <script type="text/javascript" src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <!--bootstrap-->
    <link href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <!--jquery-validator-->
    <script src="http://static.runoob.com/assets/jquery-validation-1.14.0/lib/jquery.js"></script>
    <script src="http://static.runoob.com/assets/jquery-validation-1.14.0/dist/jquery.validate.min.js"></script>
    <!--layui-->

    <script src="https://www.layuicdn.com/layui-v2.5.7/css/layui.css"></script>
    <script src="https://www.layuicdn.com/layui-v2.5.7/layui.js"></script>
    <!--<script type="text/javascript" th:src="@{/js/md5.min.js}"></script>-->
    <!--<script type="text/javascript" th:src="@{/common.js}"></script>-->
</head>
<body>
<form name="loginForm" id="loginForm" method="post" style="width: 58% ; margin: 0 auto">
    <h2 style="text-align: center ; margin-bottom: 20px">用户登录</h2>
    <div class="form-group">
        <div class="row">
            <label class="form-label col-md-4">请输入手机号码</label>
            <div class="col-md-5">
                <input id="mobile" name="mobile" class="form-control" type="text" placeholder="手机号码"
                      required="true" minlength="11" maxlength="11"/>
            </div>
        </div>
    </div>

    <div class="form-group">
        <div class="row">
            <label class="form-label col-md-4">请输入密码</label>
            <div class="col-md-5">
                <input id="password" name="password" class="form-control" type="password" placeholder="密码"
                       required="true" minlength="6" maxlength="30"/>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-md-5">
            <button class="btn btn-primary btn-block" type="reset" onclick="reset()">重置</button>
        </div>
        <div class="col-md-5">
            <button class="btn btn-primary btn-block" type="submit" onclick="login()">登录</button>
        </div>

    </div>
</form>

</body>
<script>
    layui.use(['laypage', 'layedit','layer'], function(){
        var laypage = layui.laypage
            ,layedit = layui.layedit
            ,layer = layui.layer ;

        //do something
    });
    function login() {
        $("#loginForm").validate({
            submitHandler: function (form) {
                doLogin();
            }
        });
    }
    function doLogin() {

        $.ajax({
            url:"/login/doLogin",
            type:"POST",
            data:{
                mobile: $("#mobile").val(),
                password: $("#password").val()
            },
            success: function (data) {
                if(data.code == 200){

                    layer.msg("成功");
                    window.location.href = "/goods/toList"
                }else {
                    layer.msg(data.message);
                }
            },
            error: function () {

                layer.msg(123);
            }
        });


    }
    // function g_showLoading() {
    //     var idx = layer.msg('处理中..',{icon: 16 ,shade: [0.5,'#f5f5f5'],scrollbar: false ,offset: '0px',time:100000})
    //     return idx;
    //
    // }
</script>
</html>